package model;


import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author gubengang
 * @create 2021-09-30 19:09
 */
public class Job {
    private Integer jobId;
    private Integer calcSpeed;
    private List<Block> blocks;

    public Integer getJobId() {
        return jobId;
    }

    public void setJobId(Integer jobId) {
        this.jobId = jobId;
    }

    public Integer getCalcSpeed() {
        return calcSpeed;
    }

    public void setCalcSpeed(Integer calcSpeed) {
        this.calcSpeed = calcSpeed;
    }

    public List<Block> getBlocks() {
        return blocks;
    }

    public Map<Integer, Block> groupBlockIdMap(){
        return blocks.stream().collect(Collectors.toMap(Block::getBlockId, Function.identity()));
    }

    public void setBlocks(List<Block> blocks) {
        this.blocks = blocks;
    }

    public double getSpeedRate(int coreSize){
        if(coreSize ==1){
            return calcSpeed;
        }

        if(coreSize<30){
            return -0.0002*Math.pow(coreSize, 2)-0.0063*coreSize+1.00065;
        }else{
            return 19.125/coreSize;
        }
    }

    public double getNetworkTranceTime(Integer blockSize){
        return blockSize*1.0/131072;
    }
}
